package icasue.net.socket.model.md.channel;

import com.alibaba.fastjson.JSONObject;
import icasue.net.base.annotations.NotNull;
import icasue.net.socket.model.register.RegisterInfo;
import icasue.net.socket.share.Checking;


/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/3/22 下午2:22
 * @UpdateDate:
 * @Description:
 */
public class ChannelJoin implements Checking {
    private RegisterInfo registerInfo;
    private Object channelId;

    public static ChannelJoin parse(@NotNull JSONObject json, @NotNull Class<? extends RegisterInfo> regInfoCls){
        ChannelJoin channelJoin = new ChannelJoin();
        channelJoin.setChannelId(json.remove("channelId"));
        channelJoin.setRegisterInfo(json.getJSONObject("registerInfo").toJavaObject(regInfoCls));
        return channelJoin;
    }

    @Override
    public boolean checkValid() {
        return registerInfo != null && registerInfo.checkValid() && channelId != null;
    }

    public RegisterInfo getRegisterInfo() {
        return registerInfo;
    }

    public void setRegisterInfo(RegisterInfo registerInfo) {
        this.registerInfo = registerInfo;
    }

    public Object getChannelId() {
        return channelId;
    }

    public void setChannelId(Object channelId) {
        this.channelId = channelId;
    }
}
